<?php
    include('../function/checkAdminAccess.php');
    $iniVars = parse_ini_file('../../config.ini',TRUE);
    include('../../classes/adodb5/adodb.inc.php');
    include('../../function/db.func.php');
    
    $pwId = $_GET['pwid'];
    
    $sql = "SELECT pw_msg,pw_show_in,pw_active,pw_title FROM pride_work WHERE pw_id=$pwId";
    $result = $db->Execute($sql);
    
    if($result->fields['pw_active']==1){
        $radioActive = ' checked="checked"';
        $radioUnActive = '';
    }else{
        $radioActive = '';
        $radioUnActive = ' checked="checked"';
    }
    
    if($result->fields['pw_show_in']==0){
        $radioShowIn1 = ' checked="checked"';
        $radioShowIn2 = '';
    }else{
        $radioShowIn1 = '';
        $radioShowIn2 = ' checked="checked"';
    }
?>
<script type="text/javascript">
    $(document).ready(function(){
        
        $('.button').click(function(){
            if(trim($('#prideWorkTitle').val())=='')
            {
                alert('กรุณากรอก Title');
            }
            else if(trim($('#prideWorkMsg').val())=='')
            {
                alert('กรุณากรอกข้อความ');
            }
            else
            {
                $('.ajax_load_img').css('display','inline');
                var str = $('#prideWorkAddFrm').serialize();
                $.post('function/prideWorkEdit.php',str,function(data){
                    $('.ajax_load_img').css('display','none');
                    if(trim(data)=='success'){
                        $("#success_msg").html('แก้ไขข้อมูลเรียบร้อยแล้ว');
                        $("#success_msg").show('highlight',3000,function(){
                            $("#success_msg").hide('highlight',3000);
                        });
                        setInterval('location.reload();',3000);
                    }else{
                        $("#error_msg").html('ไม่สามารถแก้ไขข้อมูลได้ กรุณาลองใหม่อีกครั้งภายหลัง');
                        $("#error_msg").show('highlight',3000,function(){
                            $("#error_msg").hide('highlight',3000);
                        });
                        setInterval('location.reload();',3000);
                    }
                });
            }
        });
        
    });
    
</script>
<form name="prideWorkAddFrm" id="prideWorkAddFrm">
    <p id="prideWorkAddFrmImg">
        <label>Title : </label>
        <input type="text" name="prideWorkTitle" id="prideWorkTitle" value="<?php echo $result->fields['pw_title']; ?>" />
    </p>
    <p id="prideWorkAddFrmMsg">
        <label>Message : </label>
        <textarea name="prideWorkMsg" id="prideWorkMsg"><?php echo $result->fields['pw_msg']; ?></textarea>
    </p>
    <p id="prideWorkAddFrmSection">
        <input type="radio" name="prideWorkSection" value="0" <?php echo $radioShowIn1; ?>/> ผลงานล่าสุด
        &nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="prideWorkSection" value="1" <?php echo $radioShowIn2; ?>/> ผลงานในปีที่ผ่านมา
    </p>
    <p id="prideWorkAddFrmActive">
        <input type="radio" name="prideWorkActive" value="1" <?php echo $radioActive; ?>/> Show
        &nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="prideWorkActive" value="0" <?php echo $radioUnActive; ?>/> Hide
    </p>
    <input type="button" class="button" value="Save" />
    <input type="hidden" name="pwId" value="<?php echo $pwId; ?>" />
    &nbsp;<img src="images/ajax-loader.gif" class="ajax_load_img submit_indicator"/>
</form>
<div class="information canhide png_bg ajax_msg"></div>
<div class="fail canhide png_bg ajax_msg" id="error_msg"></div>
<div class="success canhide ajax_msg" id="success_msg"></div>